// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ml
{
	public sealed partial class TrainedModelTree
	{
		[JsonInclude]
		[JsonPropertyName("classification_labels")]
		public IEnumerable<string>? ClassificationLabels { get; set; }

		[JsonInclude]
		[JsonPropertyName("feature_names")]
		public IEnumerable<string> FeatureNames { get; set; }

		[JsonInclude]
		[JsonPropertyName("target_type")]
		public string? TargetType { get; set; }

		[JsonInclude]
		[JsonPropertyName("tree_structure")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Ml.TrainedModelTreeNode> TreeStructure { get; set; }
	}

	public sealed partial class TrainedModelTreeDescriptor : SerializableDescriptorBase<TrainedModelTreeDescriptor>
	{
		internal TrainedModelTreeDescriptor(Action<TrainedModelTreeDescriptor> configure) => configure.Invoke(this);
		public TrainedModelTreeDescriptor() : base()
		{
		}

		private IEnumerable<string>? ClassificationLabelsValue { get; set; }

		private IEnumerable<string> FeatureNamesValue { get; set; }

		private string? TargetTypeValue { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Ml.TrainedModelTreeNode> TreeStructureValue { get; set; }

		private TrainedModelTreeNodeDescriptor TreeStructureDescriptor { get; set; }

		private Action<TrainedModelTreeNodeDescriptor> TreeStructureDescriptorAction { get; set; }

		private Action<TrainedModelTreeNodeDescriptor>[] TreeStructureDescriptorActions { get; set; }

		public TrainedModelTreeDescriptor ClassificationLabels(IEnumerable<string>? classificationLabels)
		{
			ClassificationLabelsValue = classificationLabels;
			return Self;
		}

		public TrainedModelTreeDescriptor FeatureNames(IEnumerable<string> featureNames)
		{
			FeatureNamesValue = featureNames;
			return Self;
		}

		public TrainedModelTreeDescriptor TargetType(string? targetType)
		{
			TargetTypeValue = targetType;
			return Self;
		}

		public TrainedModelTreeDescriptor TreeStructure(IEnumerable<Elastic.Clients.Elasticsearch.Ml.TrainedModelTreeNode> treeStructure)
		{
			TreeStructureDescriptor = null;
			TreeStructureDescriptorAction = null;
			TreeStructureDescriptorActions = null;
			TreeStructureValue = treeStructure;
			return Self;
		}

		public TrainedModelTreeDescriptor TreeStructure(TrainedModelTreeNodeDescriptor descriptor)
		{
			TreeStructureValue = null;
			TreeStructureDescriptorAction = null;
			TreeStructureDescriptorActions = null;
			TreeStructureDescriptor = descriptor;
			return Self;
		}

		public TrainedModelTreeDescriptor TreeStructure(Action<TrainedModelTreeNodeDescriptor> configure)
		{
			TreeStructureValue = null;
			TreeStructureDescriptor = null;
			TreeStructureDescriptorActions = null;
			TreeStructureDescriptorAction = configure;
			return Self;
		}

		public TrainedModelTreeDescriptor TreeStructure(params Action<TrainedModelTreeNodeDescriptor>[] configure)
		{
			TreeStructureValue = null;
			TreeStructureDescriptor = null;
			TreeStructureDescriptorAction = null;
			TreeStructureDescriptorActions = configure;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (ClassificationLabelsValue is not null)
			{
				writer.WritePropertyName("classification_labels");
				JsonSerializer.Serialize(writer, ClassificationLabelsValue, options);
			}

			writer.WritePropertyName("feature_names");
			JsonSerializer.Serialize(writer, FeatureNamesValue, options);
			if (!string.IsNullOrEmpty(TargetTypeValue))
			{
				writer.WritePropertyName("target_type");
				writer.WriteStringValue(TargetTypeValue);
			}

			if (TreeStructureDescriptor is not null)
			{
				writer.WritePropertyName("tree_structure");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, TreeStructureDescriptor, options);
				writer.WriteEndArray();
			}
			else if (TreeStructureDescriptorAction is not null)
			{
				writer.WritePropertyName("tree_structure");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new TrainedModelTreeNodeDescriptor(TreeStructureDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (TreeStructureDescriptorActions is not null)
			{
				writer.WritePropertyName("tree_structure");
				writer.WriteStartArray();
				foreach (var action in TreeStructureDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new TrainedModelTreeNodeDescriptor(action), options);
				}

				writer.WriteEndArray();
			}
			else
			{
				writer.WritePropertyName("tree_structure");
				JsonSerializer.Serialize(writer, TreeStructureValue, options);
			}

			writer.WriteEndObject();
		}
	}
}